home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / ultmtpch.lha / UPS / Sources / SetFunction.s < prev    next >
Text File  |  1995-09-22  |  11KB  |  576 lines

  1. ;TOSAAAACDICAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPPPPNMHO
  2.  
  3.     incdir    'ups:'
  4.     include    'ups.i'
  5.     incdir    'include:'
  6.     include    'exec/exec.i'
  7.     include    'exec/ports.i'
  8.     include    'exec/libraries.i'
  9.     include    'dos/dosextens.i'
  10.     include    'libraries/commodities.i'
  11.     include    'utility/tagitem.i'
  12.     include    'libs/exec.i'
  13.     include    'libs/commodities.i'
  14.  
  15. GetProgramName        equ    -576
  16. FilePart        equ    -870
  17. MatchPatternNoCase    equ    -972
  18. ParsePatternNoCase    equ    -966
  19.  
  20.  
  21.     SECTION    SetFunction,code_p
  22.  
  23.     movem.l    d0-d7/a0-a6,-(a7)
  24.     bsr.s    start
  25.     movem.l    (a7)+,d0-d7/a0-a6
  26.     rts
  27.  
  28. start    sub.l    a1,a1
  29.     move.l  4,a6
  30.     jsr    FindTask(a6)
  31.     move.l    d0,a4
  32.     move.l    d0,task
  33.     tst.l    pr_CLI(a4)
  34.     bne.s   fromCLI
  35.     lea    pr_MsgPort(a4),a0
  36.     jsr    WaitPort(A6)
  37.     lea    pr_MsgPort(a4),a0
  38.     jsr    GetMsg(A6)
  39.     move.l    d0,returnMsg
  40. fromCLI    jsr    start2
  41.     tst.l    returnMsg        ; Is there a message?
  42.     beq.s    exitToDOS        ; if not, skip...
  43.     move.l    4,a6
  44.         jsr    Forbid(a6)              ; note! No Permit needed!
  45.     move.l    returnMsg,a1
  46.     jsr    ReplyMsg(a6)
  47. exitToDOS
  48.     rts
  49.  
  50. returnMsg dc.l    0
  51.  
  52.     SECTION    SetFunctionMain,code_p
  53.  
  54. start2    move.l    4,a6
  55. ;    lea    upsname,a1
  56. ;    jsr    FindTask(a6)
  57. ;    tst.l    d0
  58. ;    beq.w    .exit1
  59. ;    move.l    d0,upstask
  60.     lea    cxname,a1
  61.     move.l    #36,d0
  62.     jsr    OpenLibrary(a6)
  63.     tst.l    d0
  64.     beq.w    .exit1
  65.     move.l    d0,cxbase
  66. ;    jsr    CreateMsgPort(a6)
  67. ;    tst.l    d0
  68. ;    beq.w    .exit2
  69. ;    move.l    d0,repport
  70.     jsr    CreateMsgPort(a6)
  71.     tst.l    d0
  72.     beq.w    .exit3
  73.     move.l    d0,cxport
  74.     moveq    #-1,d0
  75.     jsr    AllocSignal(a6)
  76.     cmp.b    #-1,d0
  77.     beq.w    .exit35
  78.     moveq    #1,d1
  79.     lsl.l    d0,d1
  80.     move.l    d0,signal
  81.     move.l    d1,exitbits
  82.     move.l    cxport,a0
  83.     clr.l    d1
  84.     move.b    MP_SIGBIT(a0),d1
  85.     moveq    #1,d0
  86.     lsl.l    d1,d0
  87.     move.l    d0,cxbits
  88.     move.l    cxbase,a6
  89.     clr.l    d0
  90.     lea    newbroker,a0
  91.     jsr    CxBroker(a6)
  92.     tst.l    d0
  93.     beq.w    .exit4
  94.     move.l    d0,broker
  95.     move.l    d0,a0
  96.     moveq    #1,d0
  97.     jsr    ActivateCxObj(a6)
  98.     move.l    4,a6
  99.     lea    upsportname,a1
  100.     jsr    FindPort(a6)
  101.     tst.l    d0
  102.     beq.w    .exit5
  103.     move.l    d0,upsport
  104.     move.l    #umAllocUPS,d7
  105.     lea    cxname2,a0
  106.     bsr.w    SendMessage
  107.     lea    patcher,a0
  108.     move.l    #umInstall,d7
  109.     bsr.w    SendMessage
  110.     tst.l    d0
  111.     bne.w    .exit6
  112.  
  113. .loop    move.l    exitbits,d0
  114.     or.l    cxbits,d0
  115.     jsr    Wait(a6)
  116. .loop2    and.l    exitbits,d0
  117.     tst.l    d0
  118.     bne.w    .exit6
  119.     move.l    cxport,a0
  120.     jsr    GetMsg(a6)
  121.     tst.l    d0
  122.     beq.s    .eloop2
  123.     move.l    d0,-(a7)
  124.     move.l    d0,a0
  125.     move.l    cxbase,a6
  126.     jsr    CxMsgType(a6)
  127.     cmp.l    #CXM_COMMAND,d0
  128.     bne.s    .skip
  129.     move.l    (a7)+,a0
  130.     jsr    CxMsgID(a6)
  131.     cmp.l    #CXCMD_DISABLE,d0
  132.     beq.s    .disabl
  133.     cmp.l    #CXCMD_ENABLE,d0
  134.     beq.s    .enable
  135.     cmp.l    #CXCMD_KILL,d0
  136.     beq.s    .exit7
  137.     bra.s    .skip
  138. .disabl    move.l    broker,a0
  139.     clr.l    d0
  140.     jsr    ActivateCxObj(a6)
  141.     bra.s    .skip
  142. .enable    move.l    broker,a0
  143.     moveq    #1,d0
  144.     jsr    ActivateCxObj(a6)
  145. .skip    move.l    4,a6
  146. .eloop2    bra.w    .loop
  147.  
  148.  
  149. .exit7    clr.l    done
  150.     move.l    4,a6
  151.     move.l    #umRemove,d7
  152.     lea    patcher,a0
  153.     bsr.s    SendMessage
  154. .exit6    move.l    4,a6
  155.     move.l    #umFreeUPS,d7
  156.     lea    cxname2,a0
  157.     bsr.s    SendMessage
  158. .exit5    move.l    cxbase,a6
  159.     move.l    broker,a0
  160.     jsr    DeleteCxObjAll(a6)
  161. .exit4    move.l    4,a6
  162.     move.l    signal,d0
  163.     jsr    FreeSignal(a6)
  164. .exit35    move.l    4,a6
  165.     move.l    cxport,a0
  166.     jsr    DeleteMsgPort(a6)
  167. .exit3    ;move.l    4,a6
  168. ;    move.l    repport,a0
  169. ;    jsr    DeleteMsgPort(a6)
  170. .exit2    move.l    4,a6
  171.     move.l    cxbase,a1
  172.     jsr    CloseLibrary(a6)
  173. .exit1    rts
  174.  
  175.  
  176. SendMessage
  177.     move.l    a6,-(a7)
  178.     move.l    4,a6
  179.     lea    message,a4
  180.     move.l    a0,um_A0(a4)
  181.     move.l    a1,um_A1(a4)
  182.     move.l    d0,um_D0(a4)
  183.     move.l    d1,um_D1(a4)
  184.     or.l    #umNoFree,d7
  185.     move.l    d7,um_Command(a4)
  186.     movem.l    d1-d7/a0-a6,-(a7)
  187.     jsr    CreateMsgPort(a6)
  188.     movem.l    (a7)+,d1-d7/a0-a6
  189.     tst.l    d0
  190.     beq.w    .exit
  191.     move.l    d0,repport
  192.     move.l    repport,MN_REPLYPORT(a4)
  193.     move.w    #um_SIZEOF,MN_LENGTH(a4)
  194.     move.l    a4,a1
  195.     move.l    upsport,a0
  196.     jsr    PutMsg(a6)
  197.     move.l    repport,a0
  198.     clr.l    d1
  199.     move.b    MP_SIGBIT(a0),d1
  200.     moveq    #1,d0
  201.     lsl.l    d1,d0
  202.     jsr    Wait(a6)
  203.     move.l    repport,a0
  204.     jsr    GetMsg(a6)
  205.     move.l    d0,-(a7)
  206. .loop    move.l    repport,a0
  207.     jsr    GetMsg(a6)
  208.     tst.l    d0
  209.     bne.s    .loop
  210.     move.l    (a7)+,a4
  211.     move.l    um_A0(a4),a0
  212.     move.l    um_A1(a4),a1
  213.     move.l    um_D0(a4),d0
  214.     move.l    um_D1(a4),d1
  215.     movem.l    d0-d7/a0-a6,-(a7)
  216.     move.l    repport,a0
  217.     jsr    DeleteMsgPort(a6)
  218.     movem.l    (a7)+,d0-d7/a0-a6
  219. .exit    move.l    (a7)+,a6
  220.     rts
  221.  
  222.  
  223. MsgExit    tst.l    done
  224.     beq.s    .no
  225.     movem.l    d0-d7/a0-a6,-(a7)
  226.     move.l    4,a6
  227.     move.l    task,a1
  228.     move.l    exitbits,d0
  229.     jsr    Signal(a6)
  230.     movem.l    (a7)+,d0-d7/a0-a6
  231. .no    rts
  232.  
  233.  
  234.  
  235.  
  236.  
  237.     SECTION    Data,data_p
  238. ver    dc.b    '$VER: SetFunction patcher for Ultimate Patch System.',0
  239. cxname    dc.b    'commodities.library',0
  240. upsname    dc.b    'Ultimate Patch System',0
  241.     cnop    0,4
  242. ;upstask    dc.l    0
  243. cxbase    dc.l    0
  244. repport    dc.l    0
  245. cxbits    dc.l    0
  246. exitbits
  247.     dc.l    0
  248. signal    dc.l    0
  249. broker    dc.l    0
  250. done    dc.l    1
  251. task    dc.l    0
  252. oldfunc    dc.l    0
  253. newbroker
  254.     dc.b    NB_VERSION,0
  255.     dc.l    cxname2
  256.     dc.l    cxtitle
  257.     dc.l    cxdescr
  258.     dc.w    NBU_UNIQUE,0
  259.     dc.b    0,0
  260. cxport    dc.l    0
  261.     dc.w    0
  262.  
  263. cxname2    dc.b    'SetFunction',0
  264. cxtitle    dc.b    'SetFunction Patcher V1.0',0
  265. cxdescr    dc.b    '  by Goran Mitrovic in 1995.',0
  266. upsportname
  267.     dc.b    'Ultimate Patch System',0
  268. mask    dc.b    '#?.library',0
  269.     cnop    0,4
  270. upsport    dc.l    0
  271.  
  272. message    blk.b    um_SIZEOF
  273.  
  274.  
  275. patcher    blk.b    32
  276.     dc.l    pfsControlLong
  277.     dc.l    0            ; pointer to next patcher
  278.     dc.l    0            ; pointer to prev patcher
  279.     dc.l    UPSMainVersion        ; minimum version of UPS to start
  280.     dc.l    UPSMainVersion        ; version of UPS which was used
  281.                     ; while patcher was developed
  282.     dc.l    PatcherName        ; pointer to name of patcher
  283.     dc.w    0,0            ; version
  284.     dc.l    CoderName        ; pointer to name of programmer
  285.     dc.l    ver            ; pointer to $VER: string
  286.     dc.l    PatcherIDString        ; listview entry
  287.     dc.l    pfsDisableable        ; flags
  288.     dc.l    0            ; status of flags
  289. execbase
  290.     dc.l    0            ; exec base
  291. intbase    dc.l    0            ; intuition base
  292. gadtbase
  293.     dc.l    0            ; gadtools base
  294. dosbase    dc.l    0            ; dos base
  295. gfxbase    dc.l    0            ; graphics base
  296. ccxbase    dc.l    0            ; commodities base
  297. laybase    dc.l    0            ; layers base
  298. upsbase    dc.l    0            ; UPS lib base
  299.     dc.l    0            ; pointer to init routine
  300.     dc.l    MsgExit            ; pointer to exit routine
  301.     dc.l    0            ; pointer to prefs routine
  302.     dc.l    0            ; pointer to cx keys to call prefs rout
  303.     dc.l    Resources        ; pointer to structure of requested
  304.                         ; opened resources
  305.     dc.l    Patch1            ; pointer to structure for patches
  306.     dc.l    pls1            ; pointer to pls structure
  307.     dc.l    0            ; pointer to main UPS msg port
  308.     dc.l    0            ; pointer to rexx port
  309.     dc.l    0            ; pointer to pxs structure
  310. semaphore
  311.     dc.l    0
  312.     dc.l    0,0
  313.     dc.l    pfsControlLong
  314.     dc.l    patcher            ; pointer to the beginning of struct
  315.  
  316. CoderName
  317.     dc.b    'Goran Mitrovic',0
  318. PatcherName
  319. PatcherIDString
  320.     dc.b    'SetFunction',0                ; 25
  321.     cnop    0,4
  322.  
  323.  
  324. Resources
  325.     dc.l    0            ; pointer to next entry
  326.     dc.l    0            ; pointer to previous entry
  327.     dc.l    rt_Library        ; type of resource
  328.     dc.l    100            ; resource id
  329.     dc.l    0            ; flags
  330.     dc.l    res1name        ; pointer to name of resource
  331. res1base
  332.     dc.l    0            ; base of opened resource
  333.     dc.l    0            ; version, if needed
  334.     blk.l    8            ; ...to put in data regs
  335.     dc.l    0            ; user open rout for user type
  336.     dc.l    0            ; user close rout for user type
  337.     dc.l    0            ; pointer to name for user type
  338.     dc.l    0,0
  339.  
  340. res1name
  341.     dc.b    'exec.library',0
  342.     cnop    0,4
  343.  
  344.  
  345. Patch1
  346.     dc.l    0            ; pointer to next patch
  347.     dc.l    0            ; pointer to prev patch
  348.     dc.l    30000            ; priority, less runs first
  349.     dc.l    patcher            ; pointer to parent Patcher
  350.     dc.l    Patch1ID        ; listview entry
  351.     dc.l    Patch1purpose        ; pointer to purpose string
  352.     dc.l    100            ; id of resource to be patched
  353.     dc.l    mpsDisableable        ; flags
  354.     dc.l    0            ; status of flags
  355.     dc.l    -420            ; offset to change
  356.     dc.l    setfunction        ; pointer to new routine
  357.     dc.l    0            ; pointer to old routine
  358.     dc.l    0            ; pointer to pns structure
  359.     dc.l    0            ; notified when enabled/disabled
  360.     dc.l    0            ; install rout for user type
  361.     dc.l    0            ; uninstall rout for user type
  362.     dc.l    0            ; pointer to init routine
  363.     dc.l    0            ; pointer to exit routine
  364.     dc.l    pls1            ; pointer to pls structure
  365.     dc.l    0,0,0,0
  366.  
  367.  
  368. Patch1ID
  369.     dc.b    'SetFunction',0                ; 27
  370.     even
  371. Patch1purpose
  372.     dc.b    'replacement',0                ; 16
  373.     cnop    0,4
  374.  
  375.  
  376.  
  377. pls1    dc.l    0            ; pointer to next link
  378.     dc.l    0            ; pointer to prev link
  379.     dc.l    pls1ID            ; listview string
  380.     dc.l    0            ; pointer to prefs routine
  381.     dc.l    plsDisableable        ; flags
  382.     dc.l    0            ; status
  383.     dc.l    Patch1
  384.     dc.l    0
  385.  
  386. pls1ID    dc.b    'Main Entry',0                ; 27
  387.     cnop    0,4
  388.  
  389. list    dc.l    0
  390.  
  391.  
  392.     SECTION    PatchCode,code_p
  393.  
  394.  
  395. setfunction
  396.     movem.l    d0-d7/a0-a6,-(a7)
  397.     movem.l    d0/a0/a1,-(a7)
  398.     move.l    4,a6
  399.  
  400.     cmp.l    4,a1
  401.     bne.w    .ok2
  402.     cmp.w    #-420,a0
  403.     beq.s    .aa
  404.  
  405. .ok2    movem.l    d0-d7/a0-a6,-(a7)
  406.     move.l    dosbase,a6
  407.     move.l    LN_NAME(a1),-(a7)
  408.     move.l    #mask,d1
  409.     move.l    #destmask,d2
  410.     move.l    #1024,d3
  411.     jsr    ParsePatternNoCase(a6)
  412.     move.l    #destmask,d1
  413.     move.l    (a7)+,d2
  414.     jsr    MatchPatternNoCase(a6)
  415.     tst.b    d0
  416.     beq.s    .no
  417.     bra.s    .ok
  418. .no    movem.l    (a7)+,d0-d7/a0-a6
  419.     bra.s    .aa
  420. .ok    movem.l    (a7)+,d0-d7/a0-a6
  421. ;    move.l    semaphore,a0
  422. ;    move.w    (a0),d0
  423. ;    tst.w    d0
  424.     bra.s    New
  425. .aa    movem.l    (a7)+,d0/a0/a1
  426.     movem.l    (a7)+,d0-d7/a0-a6
  427.     rts
  428.  
  429. New    movem.l    (a7)+,d0/a0/a1
  430.     move.l    list,a2
  431. .loop1    cmp.l    #0,a2
  432.     beq.s    .eloop1
  433.     move.l    sf_Offset(a2),d1
  434.     cmp.w    d1,a0
  435.     bne.w    .cont1
  436.     cmp.l    sf_Base(a2),a1
  437.     bne.s    .cont1
  438.     cmp.l    sf_Old(a2),d0
  439.     beq.w    RestOld
  440. .cont1    move.l    sf_Next(a2),a2
  441.     bra.s    .loop1
  442. .eloop1    movem.l    d0-d7/a0/a1/a3-a6,-(a7)
  443.     move.l    #sf_SIZEOF,d0
  444.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  445.     jsr    AllocVec(a6)
  446.     move.l    d0,a2
  447.     movem.l    (a7)+,d0-d7/a0/a1/a3-a6
  448.     cmp.l    #0,a2
  449.     beq.w    .exit
  450.     clr.l    d1
  451.     move.w    a0,d1
  452.     ext.l    d1
  453.     move.l    d1,sf_Offset(a2)
  454.     move.l    a1,sf_Base(a2)
  455.     move.l    d0,sf_New(a2)
  456. ;    moveq    #6,d2
  457. ;    mulu.w    d1,d2
  458.     move.l    a1,a3
  459. ;    adda.l    d2,a3
  460.     adda.l    d1,a3
  461.     addq.l    #2,a3
  462.     move.l    (a3),sf_Old(a2)
  463.     move.l    (a3),-(a7)
  464.     move.l    #umMakeEasyPatch,d7
  465.     move.l    LN_NAME(a1),libname
  466.     move.w    LIB_VERSION(a1),libver+2
  467.     move.l    d1,offset
  468.     move.l    d0,patch
  469.     movem.l    d1-d7/a0-a6,-(a7)
  470.     sub.l    a1,a1
  471.     jsr    FindTask(a6)
  472.     movem.l    (a7)+,d1-d7/a0-a6
  473.     move.l    d0,a3
  474.     movem.l    d0-d7/a0-a6,-(a7)
  475.     move.l    dosbase,a6
  476.     move.l    #taskname,d1
  477.     move.l    #1023,d2
  478.     jsr    GetProgramName(a6)
  479.     tst.b    d0
  480.     beq.s    .task
  481.     move.l    #taskname,d1
  482.     jsr    FilePart(a6)
  483.     move.l    d0,idstr
  484.     bra.s    .notask    
  485. .task    move.l    LN_NAME(a3),idstr
  486. .notask    movem.l    (a7)+,d0-d7/a0-a6
  487.     lea    taglist,a0
  488.     lea    patcher,a1
  489.     movem.l    d0-d7/a1-a6,-(a7)
  490.     jsr    SendMessage
  491.     movem.l    (a7)+,d0-d7/a1-a6
  492.     move.l    a0,sf_Patch(a2)
  493.     cmp.l    #0,a0
  494.     bne.s    .lab1
  495.     move.l    a2,a1
  496.     jsr    FreeVec(a6)
  497.     bra.s    .exit2
  498. .lab1    tst.l    list
  499.     beq.s    .lab2
  500.     move.l    list,a3
  501.     move.l    a2,sf_Prev(a3)
  502.     move.l    a3,sf_Next(a2)
  503. .lab2    move.l    a2,list
  504. .exit2    move.l    (a7)+,oldfunc
  505. .exit    movem.l    (a7)+,d0-d7/a0-a6
  506.     move.l    oldfunc,d0
  507.     addq.l    #4,a7
  508.     rts
  509.  
  510. RestOld    move.l    sf_New(a2),-(a7)
  511.     move.l    sf_Patch(a2),a0
  512.     move.l    #umFreeEasyPatch,d7
  513.     movem.l    d0-d7/a0-a6,-(a7)
  514.     jsr    SendMessage
  515.     movem.l    (a7)+,d0-d7/a0-a6
  516.     tst.l    sf_Next(a2)
  517.     beq.s    .lab1
  518.     move.l    sf_Next(a2),a3
  519.     move.l    sf_Prev(a2),sf_Prev(a3)
  520. .lab1    tst.l    sf_Prev(a2)
  521.     beq.s    .lab2
  522.     move.l    sf_Prev(a2),a3
  523.     move.l    sf_Next(a2),sf_Next(a3)
  524.     bra.s    .lab3
  525. .lab2    move.l    sf_Next(a2),list
  526.     move.l    a2,a1
  527.     jsr    FreeVec(a6)
  528. .lab3    move.l    (a7)+,oldfunc
  529.     movem.l    (a7)+,d0-d7/a0-a6
  530.     move.l    oldfunc,d0
  531.     addq.l    #4,a7
  532.     rts
  533.  
  534.  
  535. taglist    dc.l    umTagResourceType,rt_Library
  536.     dc.l    umTagResourceName
  537. libname    dc.l    0
  538.     dc.l    umTagResourceVersion
  539. libver    dc.l    0
  540. ;    dc.l    umTagResourceID,100
  541.     dc.l    umTagPatchPri,20
  542.     dc.l    umTagPatchPurposeString
  543.     dc.l    purpose
  544.     dc.l    umTagPatchIDString
  545. idstr    dc.l    0
  546.     dc.l    umTagPatchOffset
  547. offset    dc.l    0
  548.     dc.l    umTagPatchDisableable,1
  549.     dc.l    umTagPatchFullPatch,1
  550.     dc.l    umTagPatch
  551. patch    dc.l    0
  552.     dc.l    umTagPatchNotifyDisable,0
  553.     dc.l    umTagPatchInit,0
  554.     dc.l    umTagPatchExit,0
  555.     dc.l    TAG_DONE,0
  556.  
  557. purpose    dc.b    'replacement',0
  558.  
  559.  STRUCTURE sf,0
  560.     APTR  sf_Next
  561.     APTR  sf_Prev
  562.     APTR  sf_Old
  563.     APTR  sf_New
  564.     APTR  sf_Patch
  565.     APTR  sf_Base
  566.     LONG  sf_Offset
  567.     LABEL sf_SIZEOF
  568.  
  569.  
  570.     SECTION    taskname,bss_p
  571.  
  572. taskname
  573.     ds.b    1024
  574. destmask
  575.     ds.b    1024
  576.